package pl.ptemich.pong;

import java.awt.Dimension;
import java.awt.Toolkit;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import pl.ptemich.pong.model.ScreenTools;
import pl.ptemich.pong.states.GameState;

/**
 * @author AIPT
 * 
 */
public class PongGame extends StateBasedGame {
  
  private ScreenTools screenTools;

  public PongGame(int width, int height) {
    super("Pong Game");
    this.screenTools = new ScreenTools(width, height);
  }

  @Override
  public void initStatesList(GameContainer arg0) throws SlickException { 
    addState(new GameState(screenTools)); 
  }

  /**
   * @param args
   */
  public static void main(String[] args) {
    System.out.println("Game start");
    AppGameContainer container;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    try {
      PongGame instance = new PongGame(Double.valueOf(screenSize.getWidth()).intValue(), 
                                       Double.valueOf(screenSize.getHeight()).intValue());
      
      container = new AppGameContainer(instance, 
                                       Double.valueOf(screenSize.getWidth()).intValue(), 
                                       Double.valueOf(screenSize.getHeight()).intValue(),
                                       true); // full screen
      //container.setShowFPS(true);
      container.setTargetFrameRate(75);
      container.setMouseGrabbed(true); // disable mouse cursor
      container.setVSync(true);
      container.start();
    } catch (SlickException e) {
      System.err.println("Unable to initilize screen");
    }

    System.out.println("Game end");
  }  
}
